<?php

namespace app\admin\model\serial;

use think\Model;

class Special extends Model
{
    // 表名
    protected $name = 'serial_special';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [
        'usetime_text',
        'cancel_text',
        'use_text',
        'send_text',
        'pdf_text',
        'publish_text',
        'pdf_url_text',
         'username_text',
         'phone_text',
         'name_text',
         'nb_text',
    ];
    

    
  public function getPdfUrlList()
    {
        return [ 1=>'http://image.fc62.com/diduan.pdf',2=>'http://image.fc62.com/zhongduan.pdf',3=>'http://image.fc62.com/gaoduan.pdf'];
    } 
     public function getPdfUrlTextAttr($value, $data)
    {
        $value = $value ? $value : $data['type_pdf'];
        $list = $this->getPdfUrlList();
        return isset($list[$value]) ? $list[$value] : '';
    }
  public function getCancelList()
    {
        return ['1' => __('Is_cancel 1'),'2' => __('Is_cancel 2')];
    }    
    public function getCancelTextAttr($value, $data)
    {
        $value = $value ? $value : $data['is_cancel'];
        $list = $this->getCancelList();
        return isset($list[$value]) ? $list[$value] : '';
    }   
   public function getUseList()
    {
        return ['1' => __('Is_use 1'),'2' => __('Is_use 2')];
    }  
    public function getUseTextAttr($value, $data)
    {
        $value = $value ? $value : $data['is_use'];
        $list = $this->getUseList();
        return isset($list[$value]) ? $list[$value] : '';
    } 
      public function getSendList()
    {
        return ['1' => __('Is_send 1'),'2' => __('Is_send 2')];
    }  
     public function getSendTextAttr($value, $data)
    {
        $value = $value ? $value : $data['is_send'];
        $list = $this->getSendList();
        return isset($list[$value]) ? $list[$value] : '';
    }   
      public function getTypepdfList()
    {
        return ['1' => __('Type_pdf 1'),'2' => __('Type_pdf 2'),'3' => __('Type_pdf 3')];
    }  
    public function getPdfTextAttr($value, $data)
    {
        $value = $value ? $value : $data['type_pdf'];
        $list = $this->getTypepdfList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function getPublishTextAttr($value, $data){        
        $value = $value ? $value : $data['publish'];
        $list = TableField('Admin','username',$value,'userid');
        return isset($list) ? $list : '';
    }   

    public function getUsernameTextAttr($value, $data){        
        $value = $value ? $value : $data['userid'];
        $list = TableField('WeixinUser','nickname',$value,'userid');
        return isset($list) ? $list : '';
    }   
     public function getPhoneTextAttr($value, $data){        
        $value = $value ? $value : $data['userid'];
        $list = TableField('WeixinUser','phone',$value,'userid');
        return isset($list) ? $list : '';
    }   
     public function getNameTextAttr($value, $data){        
        $value = $value ? $value : $data['userid'];
        $list = TableField('WeixinUser','name',$value,'userid');
        return isset($list) ? $list : '';
    }     
    public function getNbTextAttr($value, $data){        
        $value = $value ? $value : $data['userid'];
        $list = TableField('Management','orderid',$value,'userid');
        return isset($list) ? $list : '';
    }
    public function getUsetimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['usetime'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    protected function setUsetimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


}
